package de.ipk_gatersleben.bit.bi.edal.publication.listener;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JPanel;
import javax.swing.text.JTextComponent;

/**
 * {@link KeyListener} to switch from one {@link JPanel} to the next
 * {@link JPanel} by pressing {@link KeyEvent#VK_TAB}
 * 
 * @author arendd
 * 
 */
public class TabKeyListener implements KeyListener {

	JTextComponent nextPanel = null;

	public TabKeyListener(JTextComponent nextPanel) {

		this.nextPanel = nextPanel;
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// do nothing
	}

	@Override
	public void keyPressed(KeyEvent e) {
		if (e.getID() == KeyEvent.KEY_PRESSED
				&& e.getKeyCode() == KeyEvent.VK_TAB) {
			nextPanel.grabFocus();
		}

	}

	@Override
	public void keyReleased(KeyEvent e) {
		// do nothing
	}
}
